<!DOCTYPE html>
<html lang="en" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4"
      xmlns:th="http://www.thymeleaf.org" th:fragment="header(title,keywords)">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Insert title here</title>
</head>
<body>
<h1>登录页面</h1>
<span>用户名</span><input id="username" type="text" value="admin"><br>
<span>密码</span><input id="password" type="text" value="admin"><br>
<input type="button" value="登录" onclick="login()"/>

<script th:src="@{/assets/js/jquery.min.js}"></script>

<script type="text/javascript" th:inline="javascript">
    function login() {
        var rootUrl=[[${#httpServletRequest.getContextPath()}]];

        var username = $("#username").val();
        var password = $("#password").val();

        $.ajax({
            url: rootUrl+'/login',
            type: 'post',
            async: false,
            data: {
                username: username,
                password: password,
            },
            timeout: 5000,
            success: function (data) {
                //有错就抛错
                if (data.status == "0") {
                    alert(data.message);
                    return;
                }
                //
                var newUrl = rootUrl+"/" + data;
                $(window).attr('location', newUrl);


            },
        })

    }
</script>
</body>
</html>